package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.entity.Dish;
import com.chixing.entity.Myorder;
import com.chixing.mapper.MyorderMapper;
import com.chixing.service.IMyorderService;
import com.chixing.service.ICouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chixing.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author smith
 * @since 2025-05-21
 */
@Service
public class MyorderServiceImpl  implements IMyorderService {
    @Autowired
    private MyorderMapper myorderMapper;
    @Override
    public Result getById(Integer myoderId) {
        Myorder myorder = myorderMapper.selectById(myoderId);
        if(myoderId!=null)
            return Result.getSuccess(myorder);
        return Result.getFail(null);
    }

    @Override
    public Result saveorder(Myorder order) {
        int rows = myorderMapper.insert(order);
        if(rows >0)
            return Result.saveSuccess(order);
        return Result.saveFail(order);
    }

    @Override
    public Result getOrdersByUserId(Integer userId) {
        QueryWrapper<Myorder> wrapper = new QueryWrapper<>();
        wrapper.eq("cust_id",userId);
        List<Myorder> orderList = myorderMapper.selectList(wrapper);
        if(orderList !=null && orderList.size() >0)
            return Result.getSuccess(orderList);
        else
            return Result.getFail("没有订单");
    }

}
